with FT2.Errors; use FT2.Errors;

package body FT2.Debug is

   -----------
   -- Image --
   -----------

   function Image (X : FT_Error) return String is
   begin
      case X is
         --  Generic errors
         when FT_Err_Ok => return "no error";
         when FT_Err_Cannot_Open_Resource => return "cannot open resource";
         when FT_Err_Unknown_File_Format => return "unknown file format";
         when FT_Err_Invalid_File_Format => return "broken file";
         when FT_Err_Invalid_Version => return "invalid FreeType version";
         when FT_Err_Lower_Module_Version => return "module version is too low";
         when FT_Err_Invalid_Argument => return "invalid argument";
         when FT_Err_Unimplemented_Feature => return "unimplemented feature";
         when FT_Err_Invalid_Table => return "broken table";
         when FT_Err_Invalid_Offset => return "broken offset within table";
         when FT_Err_Array_Too_Large => return "array too large";

         -- Glyph/character errors
         when FT_Err_Invalid_Glyph_Index => return "invalid glyph index";
         when FT_Err_Invalid_Character_Code => return "invalid character code";
         when FT_Err_Invalid_Glyph_Format => return "unsupported glyph image format";
         when FT_Err_Cannot_Render_Glyph => return "cannot render this glyph format";
         when FT_Err_Invalid_Outline => return "invalid outline";
         when FT_Err_Invalid_Composite => return "invalid composite glyph";
         when FT_Err_Too_Many_Hints => return "too many hints";
         when FT_Err_Invalid_Pixel_Size => return "invalid pixel size";

         -- Handle errors
         when FT_Err_Invalid_Handle => return "invalid object handle";
         when FT_Err_Invalid_Library_Handle => return "invalid library handle";
         when FT_Err_Invalid_Driver_Handle => return "invalid module handle";
         when FT_Err_Invalid_Face_Handle => return "invalid face handle";
         when FT_Err_Invalid_Size_Handle => return "invalid size handle";
         when FT_Err_Invalid_Slot_Handle => return "invalid glyph slot handle";
         when FT_Err_Invalid_CharMap_Handle => return "invalid charmap handle";
         when FT_Err_Invalid_Cache_Handle => return "invalid cache manager handle";
         when FT_Err_Invalid_Stream_Handle => return "invalid stream handle";

         -- Driver errors
         when FT_Err_Too_Many_Drivers => return "too many modules";
         when FT_Err_Too_Many_Extensions => return "too many extensions";

         -- Memory errors
         when FT_Err_Out_Of_Memory => return "out of memory";
         when FT_Err_Unlisted_Object => return "unlisted object";

         -- Stream errors
         when FT_Err_Cannot_Open_Stream => return "cannot open stream";
         when FT_Err_Invalid_Stream_Seek => return "invalid stream seek";
         when FT_Err_Invalid_Stream_Skip => return "invalid stream skip";
         when FT_Err_Invalid_Stream_Read => return "invalid stream read";
         when FT_Err_Invalid_Stream_Operation => return "invalid stream operation";
         when FT_Err_Invalid_Frame_Operation => return "invalid frame operation";
         when FT_Err_Nested_Frame_Access => return "nested frame access";
         when FT_Err_Invalid_Frame_Read => return "invalid frame read";

         -- Raster errors
         when FT_Err_Raster_Uninitialized => return "raster uninitialized";
         when FT_Err_Raster_Corrupted => return "raster corrupted";
         when FT_Err_Raster_Overflow => return "raster overflow";
         when FT_Err_Raster_Negative_Height => return "negative height while rastering";

         -- Cache errors
         when FT_Err_Too_Many_Caches => return "too many registered caches";

         -- TrueType and SFNT errors
         when FT_Err_Invalid_Opcode => return "invalid opcode";
         when FT_Err_Too_Few_Arguments => return "too few arguments";
         when FT_Err_Stack_Overflow => return "stack overflow";
         when FT_Err_Code_Overflow => return "code overflow";
         when FT_Err_Bad_Argument => return "bad argument";
         when FT_Err_Divide_By_Zero => return "division by zero";
         when FT_Err_Invalid_Reference => return "invalid reference";
         when FT_Err_Debug_OpCode => return "found debug opcode";
         when FT_Err_ENDF_In_Exec_Stream => return "found ENDF opcode in execution stream";
         when FT_Err_Nested_DEFS => return "nested DEFS";
         when FT_Err_Invalid_CodeRange => return "invalid code range";
         when FT_Err_Execution_Too_Long => return "execution context too long";
         when FT_Err_Too_Many_Function_Defs => return "too many function definitions";
         when FT_Err_Too_Many_Instruction_Defs => return "too many instruction definitions";
         when FT_Err_Table_Missing => return "SFNT font table missing";
         when FT_Err_Horiz_Header_Missing => return "horizontal header (hhea table missing";
         when FT_Err_Locations_Missing => return "locations (loca table missing";
         when FT_Err_Name_Table_Missing => return "name table missing";
         when FT_Err_CMap_Table_Missing => return "character map (cmap table missing";
         when FT_Err_Hmtx_Table_Missing => return "horizontal metrics (hmtx table missing";
         when FT_Err_Post_Table_Missing => return "PostScript (post table missing";
         when FT_Err_Invalid_Horiz_Metrics => return "invalid horizontal metrics";
         when FT_Err_Invalid_CharMap_Format => return "invalid character map (cmap format";
         when FT_Err_Invalid_PPem => return "invalid ppem value";
         when FT_Err_Invalid_Vert_Metrics => return "invalid vertical metrics";
         when FT_Err_Could_Not_Find_Context => return "could not find context";
         when FT_Err_Invalid_Post_Table_Format => return "invalid PostScript (post table format";
         when FT_Err_Invalid_Post_Table => return "invalid PostScript (post table";

         -- CFF, CID, and Type 1 errors
         when FT_Err_Syntax_Error => return "opcode syntax error";
         when FT_Err_Stack_Underflow => return "argument stack underflow";
         when FT_Err_Ignore => return "ignore";

         -- BDF errors
         when FT_Err_Missing_Startfont_Field => return "`STARTFONT' field missing";
         when FT_Err_Missing_Font_Field => return "`FONT' field missing";
         when FT_Err_Missing_Size_Field => return "`SIZE' field missing";
         when FT_Err_Missing_Chars_Field => return "`CHARS' field missing";
         when FT_Err_Missing_Startchar_Field => return "`STARTCHAR' field missing";
         when FT_Err_Missing_Encoding_Field => return "`ENCODING' field missing";
         when FT_Err_Missing_Bbx_Field => return "`BBX' field missing";

         -- Others
         when others => return "Unknowm error (" & FT_Error'Image (X) & ")";
      end case;
   end Image;

end FT2.Debug;
